package live.sidian.database.synchronizer.infrastructure.utils;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;

/**
 * @author sidian
 * @date 2021/1/29 23:23
 */
public class Assert {
    public static void isTrue(boolean expression, String msg, Class<? extends RuntimeException> eClass) {
        if (!expression) {
            throw ReflectUtil.newInstance(eClass, msg);
        }
    }

    public static void isTrue(boolean expression, Class<? extends RuntimeException> eClass) {
        if (!expression) {
            throw ReflectUtil.newInstance(eClass);
        }
    }

    public static <T> void notNull(T object, String msg, Class<? extends RuntimeException> eClass) {
        if (object == null) {
            throw ReflectUtil.newInstance(eClass, msg);
        }
    }

    public static <T> void notNull(T object, Class<? extends RuntimeException> eClass) {
        if (object == null) {
            throw ReflectUtil.newInstance(eClass);
        }
    }

    public static void notBlank(String str, String msg, Class<? extends RuntimeException> eClass) {
        if (StrUtil.isBlank(str)) {
            throw ReflectUtil.newInstance(eClass, msg);
        }
    }

    public static void notBlank(String str, Class<? extends RuntimeException> eClass) {
        if (StrUtil.isBlank(str)) {
            throw ReflectUtil.newInstance(eClass);
        }
    }
}
